package com.dingwen.treasure.business.jackson;

import cn.hutool.json.JSONUtil;
import com.dingwen.treasure.business.model.dto.DeserializerDto;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.databind.DeserializationContext;
import com.fasterxml.jackson.databind.JsonDeserializer;
import com.fasterxml.jackson.databind.JsonNode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.jackson.JsonComponent;

import java.io.IOException;

/**
 * 　DeserializerJsonDeserializer
 * 　@author dingwen
 * 　@date 2022/5/15$
 */
@JsonComponent
@Slf4j
public class DeserializerJsonDeserializer extends JsonDeserializer<DeserializerDto> {
    @Override
    public DeserializerDto deserialize(JsonParser jsonParser, DeserializationContext deserializationContext) throws IOException {
        // 获取原参数对象
        JsonNode jsonNode = jsonParser.getCodec().readTree(jsonParser);
        DeserializerDto deserializerDto = JSONUtil.toBean(jsonNode.toString(), DeserializerDto.class);
        // 解密
        deserializerDto.setValue("已完成解密");
        return deserializerDto;
    }
}
